// 简化路径
//https://leetcode.cn/problems/simplify-path/description/?envType=study-plan-v2&envId=top-interview-150
class Solution {
public:

    string simplifyPath(string path) 
    {
        vector<string> v;
        int n = path.size();
        int left = 1, right = 1;
        while(right < n)
        {
            while(right < n && path[right] != '/') right++;
            v.push_back(path.substr(left,right - left));
            left = right = right + 1;
        }

        stack<string> st;
        for(int i = 0; i < v.size(); i++)
        {
            if(v[i] == "." || v[i] == "") continue;
            else if(v[i] == "..")
            {
                if(!st.empty())
                    st.pop();
            }
            else
            {
                st.push(v[i]);
            }
        }
        cout << "---" << endl;

        string ret;
        while(!st.empty())
        {
            ret = '/' + st.top() + ret;
            st.pop();
        }

        if(ret == "") return "/";
        return ret;
    }
};